import java.util.*;

/**
 * @description: 集合
 * @author: rock
 * @create:
 **/
public class jihe {
    //方法一
//    HashMap<String,String> h =  new HashMap<String,String>(){{
//        put("序号","1");
//        put("姓名","张三");
//        put("年龄","20");
//
//
//    }};
    //方法二
    private static Map<String,Object> map1;
    private static Map<String,Object> map2;
    private static Map<String,Object> map3;
    static {
        map1 =  new LinkedHashMap<String,Object>();
        map2 = new LinkedHashMap<String,Object>();
        map3 = new  LinkedHashMap<String,Object>();
        map1.put("序号",1);
        map1.put("姓名","张三");
        map1.put("年龄",20);
        map2.put("序号",2);
        map2.put("姓名","李四");
        map2.put("年龄",24);
        map3.put("序号",3);
        map3.put("姓名","李四");
        map3.put("年龄",24);
    }
    private static List<Map> list = new ArrayList<Map>();

    public static void main(String[] args) {
        boolean canprint = true;
        list.add(map1);
        list.add(map2);
        list.add(map3);
        for (Map m : list) {

//            Iterator iterator = m.entrySet().iterator();
            Iterator iterator = m.entrySet().iterator();
            if (canprint){
                while (iterator.hasNext()){
                    Map.Entry<String,Object> en = (Map.Entry<String, Object>) iterator.next();
                    System.out.print("    "+ en.getKey());
                                    }
                System.out.println();
                canprint = false;
            }

            while (iterator.hasNext()) {
                Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) iterator.next();
//                System.out.print(entry.getKey()+" " );
                System.out.print("    "+entry.getValue());


            }
            System.out.println();
        }
    }
    }




